/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.OpenParts.test.gwt.tests;

import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

import fr.openparts.OpenParts.client.OPMessageFromContainerSlotHandler;
import fr.openparts.OpenParts.client.OPMessagesDispatcher;
import fr.openparts.OpenParts.client.OPParams;
import fr.openparts.OpenParts.client.OPParamsJS;
import fr.openparts.OpenParts.client.OPProxyCommands;
import fr.openparts.OpenParts.client.OPSlotProxy;

/**
 * GWT tests for OPSlotProxy.
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 18 January 2011
 */
public class OPSlotProxyTestGwt extends GWTTestCase {

    private static final String SLOT_ID = "dummySlotId_slotProxy";
    private static final String MESSAGE = "dummyMessage";
    private static final String PARAM_NAME = "dummyParamName";
    private static final String PARAM_VALUE = "dummyParamValue";

    private OPSlotProxy proxy;
    private OPMessagesDispatcher dispatcher;
    private DummyMessageFromContainerSlotHandler handler;
    private DummyView view;
    private OPParams params;
    private OPParamsJS paramsjs;
    private OPParamsJS valueParamsjs;

    /**
     * Return the name of the tested GWT Module.
     * 
     * @see com.google.gwt.junit.client.GWTTestCase#getModuleName()
     */
    @Override
    public final String getModuleName() {
        return "fr.openparts.OpenParts.test.gwt.TestOpenParts";
    }

    /**
     * Called at the start of each test to set up the service.
     * 
     * @see com.google.gwt.junit.client.GWTTestCase#gwtSetUp()
     */
    @Override
    protected void gwtSetUp() throws Exception {
        super.gwtSetUp();
        proxy = new OPSlotProxy(SLOT_ID);
        dispatcher = OPMessagesDispatcher.dispatcherFactory(SLOT_ID);
        dispatcher.registerSlotProxy(proxy);
        handler = new DummyMessageFromContainerSlotHandler();
        view = new DummyView();
        params = new OPParams(PARAM_NAME, PARAM_VALUE);
        paramsjs = OPParamsJS.buildFromOPParams(params);
        valueParamsjs = OPParamsJS.buildFromOPParams(new OPParams(OPProxyCommands.OP_PROXY_PARAM_VALUE, "dummyValue"));
    }
    
    /**
     * Test constructor.
     */
    public final void testConstructor() {
        assertNotNull("Slot proxy shouldn't be null", proxy);
        assertTrue("Proxy should be registered in dispatcher", dispatcher.isMessageFromContainerSlotHandlerCallbackRegistered());
        assertFalse("Embedded view callback should not be registered in dispatcher", dispatcher.isMessageFromEmbeddedViewHandlerCallbackRegistered());
    }

    /**
     * Test constructor passing a null slot id. Should raise an assertion error.
     */
    public final void testConstructorWithNullSlotId() {
        if (assertionsAreEnabled()) {
            try {
                proxy = new OPSlotProxy(null);
                fail("OPSlotProxy should raise an assertion error when constructed with a with a null slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test constructor passing an empty slot id. Should raise an assertion error.
     */
    public final void testConstructorWithEmptySlotId() {
        if (assertionsAreEnabled()) {
            try {
                proxy = new OPSlotProxy("");
                fail("OPSlotProxy should raise an assertion error when constructed with a with an empty slot id.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }
    
    /**
     * Test getting slot id
     */
    public final void testGettingSlotId() {
        assertEquals("Should get the same slot id as passed", SLOT_ID, proxy.getSlotId());
    }
    
    /**
     * Test attaching a null view. Should raise an assertion error.
     */
    public final void testAttachingNullView() {
        if (assertionsAreEnabled()) {
            try {
                proxy.attachView(null);
                fail("OPSlotProxy should raise an assertion error when attaching a null view.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test adding a message handler. Should get true.
     */
    public final void testAddingMessageHandler() {
        assertTrue("Slot proxy should return true when registering an handler for the first time", proxy.addMessageHandler(handler));
    }

    /**
     * Test adding a null message handler. Should raise an assertion error.
     */
    public final void testAddingNullMessageHandler() {
        if (assertionsAreEnabled()) {
            try {
                proxy.addMessageHandler(null);
                fail("OPSlotProxy should raise an assertion error when adding a null message handler.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test adding two times the same message handler. First should return true, second should return false.
     */
    public final void testAddingMessageHandlerTwoTimes() {
        assertTrue("Slot proxy should return true when registering an handler for the first time", proxy.addMessageHandler(handler));
        assertFalse("Slot proxy should return false when registering an handler for the second time", proxy.addMessageHandler(handler));
    }

    /**
     * Test removing a registered message handler. Should return true.
     */
    public final void testRemovingMessageHandlerRegistered() {
        proxy.addMessageHandler(handler);
        assertTrue("Slot proxy should return true when removing registered message handler", proxy.removeMessageHandler(handler));
    }

    /**
     * Test removing an unregistered message handler. Should return false.
     */
    public final void testRemovingMessageHandlerUnregistered() {
        assertFalse("Slot proxy should return false when removing unregistered message handler",
                proxy.removeMessageHandler(new DummyMessageFromContainerSlotHandler()));
    }

    /**
     * Test removing a null message handler. Should raise an assertion error.
     */
    public final void testRemovingMessageHandlerNull() {
        if (assertionsAreEnabled()) {
            try {
                proxy.removeMessageHandler(null);
                fail("OPSlotProxy should raise an assertion error when removing a null message handler.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test removing two times the same message handler. First should return true, second should return false.
     */
    public final void testRemovingMessageHandlerTwoTimes() {
        assertTrue("Slot proxy should return true when registering an handler for the first time", proxy.addMessageHandler(handler));
        assertFalse("Slot proxy should return false when registering an handler for the second time", proxy.addMessageHandler(handler));
        assertTrue("Slot proxy should return true when removing message handler the first time", proxy.removeMessageHandler(handler));
        assertFalse("Slot proxy should return false when removing message handler the second time", proxy.removeMessageHandler(handler));
    }

    /**
     * Test dispatching message to handlers. Should get back the message and its params.
     */
    public final void testDispatchMessageWithParams() {
        proxy.addMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);

        dispatcher.dispatchMessageToEmbeddedView(MESSAGE, paramsjs);

        assertEquals("Handler should have been called now, and only once", 1, handler.counterOfTimeCalled);
        assertEquals("Handler should get message passed", MESSAGE, handler.message);
        assertNotNull("Handler should get some params passed", handler.params);
        assertEquals("passed params should contains one element", 1, handler.params.size());
    }

    /**
     * Test dispatching message with a null message. Should raise an assertion error.
     */
    public final void testDispatchingMessageWithNullMessage() {
        if (assertionsAreEnabled()) {
            try {
                dispatcher.dispatchMessageToEmbeddedView(null, paramsjs);
                fail("OPSlotProxy should raise an assertion error when dispatching a message with a null message.");
            } catch (AssertionError e) {
                assertTrue("Error should be an AssertionError", e instanceof AssertionError);
            }
        }
    }

    /**
     * Test dispatching message with null params. Should get back the message and a null params.
     */
    public final void testDispatchingMessageWithNullParams() {
        proxy.addMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);

        dispatcher.dispatchMessageToEmbeddedView(MESSAGE, null);

        assertEquals("Handler should have been called now, and only once", 1, handler.counterOfTimeCalled);
        assertEquals("Handler should get message passed", MESSAGE, handler.message);
        assertEquals("Handler should get null params", null, handler.params);
    }

    /**
     * Test dispatching message with empty params. Should get back the message and an empty params.
     */
    public final void testDispatchingMessageWithEmptyParams() {
        proxy.addMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);

        dispatcher.dispatchMessageToEmbeddedView(MESSAGE, OPParamsJS.buildFromOPParams(new OPParams()));

        assertEquals("Handler should have been called now, and only once", 1, handler.counterOfTimeCalled);
        assertEquals("Handler should get message passed", MESSAGE, handler.message);
        assertNotNull("Handler should get some params passed", handler.params);
        assertEquals("Handler should get empty params", 0, handler.params.size());
    }

    /**
     * Test dispatching message to two handlers. The two handlers should get back passed messages and params, and be called exactly once each.
     */
    public final void testDispatchingMessageToTwoHandlers() {
        DummyMessageFromContainerSlotHandler handler2 = new DummyMessageFromContainerSlotHandler();

        proxy.addMessageHandler(handler);
        proxy.addMessageHandler(handler2);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);

        dispatcher.dispatchMessageToEmbeddedView(MESSAGE, paramsjs);

        assertEquals("Handler should have been called exactly once", 1, handler.counterOfTimeCalled);
        assertEquals("Handler should get message passed", MESSAGE, handler.message);
        assertNotNull("Handler should get some params passed", handler.params);
        assertEquals("passed params should contains one element", 1, handler.params.size());

        assertEquals("Handler 2 should have been called exactly once", 1, handler2.counterOfTimeCalled);
        assertEquals("Handler 2 should get message passed", MESSAGE, handler2.message);
        assertNotNull("Handler 2 should get some params passed", handler2.params);
        assertEquals("passed params should contains one element", 1, handler2.params.size());
    }

    /**
     * Test dispatching message to a handler that tried to register 2 times. Should be called only once.
     */
    public final void testdispatchingMessageToOneHandlerRegisteredTwoTimes() {
        proxy.addMessageHandler(handler);
        proxy.addMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);

        dispatcher.dispatchMessageToEmbeddedView(MESSAGE, paramsjs);

        assertEquals("Handler should have been called exactly once", 1, handler.counterOfTimeCalled);
    }

    /**
     * Test dispatching message to a handler that registered then unregistered. Should not be called at all.
     */
    public final void testDispatchingMessageToOneHandlerUnregistered() {
        proxy.addMessageHandler(handler);
        proxy.removeMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);

        dispatcher.dispatchMessageToEmbeddedView(MESSAGE, paramsjs);

        assertEquals("Handler should not have been called at all", 0, handler.counterOfTimeCalled);
    }
    
    /**
     * Test informing handler that embedded view is attached.
     */
    public final void testEmbeddedViewAttach() {
        proxy.addMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfOnAttachCalled);

        proxy.onEmbeddedViewAttach();

        assertEquals("Handler should have been called now, and only once", 1, handler.counterOfOnAttachCalled);
    }

    /**
     * Test informing two handlers that embedded view is attached. The two handlers should be called exactly once each.
     */
    public final void testEmbeddedViewAttachTwoHandlers() {
        DummyMessageFromContainerSlotHandler handler2 = new DummyMessageFromContainerSlotHandler();

        proxy.addMessageHandler(handler);
        proxy.addMessageHandler(handler2);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfOnAttachCalled);

        proxy.onEmbeddedViewAttach();

        assertEquals("Handler should have been called exactly once", 1, handler.counterOfOnAttachCalled);
        assertEquals("Handler 2 should have been called exactly once", 1, handler2.counterOfOnAttachCalled);
    }

    /**
     * Test informing about embedded view attachment a handler that tried to register 2 times. Should be called only once.
     */
    public final void testEmbeddedViewAttachOneHandlerRegisteredTwoTimes() {
        proxy.addMessageHandler(handler);
        proxy.addMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfOnAttachCalled);

        proxy.onEmbeddedViewAttach();

        assertEquals("Handler should have been called exactly once", 1, handler.counterOfOnAttachCalled);
    }

    /**
     * Test informing about embedded view attachment a handler that registered then unregistered. Should not be called at all.
     */
    public final void testEmbeddedViewAttachOneHandlerUnregistered() {
        proxy.addMessageHandler(handler);
        proxy.removeMessageHandler(handler);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfOnAttachCalled);

        proxy.onEmbeddedViewAttach();

        assertEquals("Handler should not have been called at all", 0, handler.counterOfOnAttachCalled);
    }

    /**
     * Test checking that the slot proxy is attached to a real slot. Should return true;
     */
    public final void testProxyAttachedToRealSlot() {
        assertFalse("Proxy should not be attached yet to a real slot", proxy.isProxyAttachedToRealSlot());

        final Element element = DOM.createDiv();
        element.setId(SLOT_ID);
        RootPanel.getBodyElement().appendChild(element);
        dispatcher.attachDispatcherOnElement(element);
        registerDummyProxyInDispatcher(dispatcher);

        assertTrue("Proxy should be attached now to a real slot", proxy.isProxyAttachedToRealSlot());
    }
    
    /**
     * Test proxy command setStyleName. Should call the view corresponding method.
     */
    public final void testProxyCommandSetStyleName() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_STYLE_NAME, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should have been called now", 1, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command setStyleName with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandSetStyleNameWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_STYLE_NAME, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Test proxy command addStyleName. Should call the view corresponding method.
     */
    public final void testProxyCommandAddStyleName() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_ADD_STYLE_NAME, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should have been called now", 1, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command addStyleName with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandAddStyleNameWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_ADD_STYLE_NAME, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }

    /**
     * Test proxy command removeStyleName. Should call the view corresponding method.
     */
    public final void testProxyCommandRemoveStyleName() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_REMOVE_STYLE_NAME, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should have been called now", 1, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command removeStyleName with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandRemoveStyleNameWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_REMOVE_STYLE_NAME, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Test proxy command setStylePrimaryName. Should call the view corresponding method.
     */
    public final void testProxyCommandSetStylePrimaryName() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_STYLE_PRIMARY_NAME, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should have been called now", 1, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command setStylePrimaryName with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandSetStylePrimaryNameWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_STYLE_PRIMARY_NAME, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Test proxy command addStyleDependentName. Should call the view corresponding method.
     */
    public final void testProxyCommandAddStyleDependentName() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_ADD_STYLE_DEPENDENT_NAME, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should have been called now", 1, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command addStyleDependentName with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandAddStyleDependentNameWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_ADD_STYLE_DEPENDENT_NAME, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }

    /**
     * Test proxy command removeStyleDependentName. Should call the view corresponding method.
     */
    public final void testProxyCommandRemoveStyleDependentName() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_REMOVE_STYLE_DEPENDENT_NAME, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should have been called now", 1, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command removeStyleDependentName with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandRemoveStyleDependentNameWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_REMOVE_STYLE_DEPENDENT_NAME, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Test proxy command setWidth. Should call the view corresponding method.
     */
    public final void testProxyCommandSetWidth() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_WIDTH, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should have been called now", 1, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command setWidth with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandSetWidthWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_WIDTH, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Test proxy command setHeight. Should call the view corresponding method.
     */
    public final void testProxyCommandSetHeight() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_HEIGHT, valueParamsjs);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should have been called now", 1, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command setHeight with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandSetHeightWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_HEIGHT, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Test proxy command setSize. Should call the view corresponding method.
     */
    public final void testProxyCommandSetSize() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        final OPParamsJS doubleValuesParamsJS = OPParamsJS.buildFromOPParams(new OPParams(OPProxyCommands.OP_PROXY_PARAM_VALUE_1, "dummyValue1", OPProxyCommands.OP_PROXY_PARAM_VALUE_2, "dummyValue2"));
        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_SIZE, doubleValuesParamsJS);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should have been called now", 1, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command setHeight with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandSetSizeWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_SIZE, paramsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
        
        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_SIZE, valueParamsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 2, handler.counterOfTimeCalled);
    }
    
    /**
     * Test proxy command setVisible. Should call the view corresponding method.
     */
    public final void testProxyCommandSetVisible() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        final OPParamsJS trueParamsJS = OPParamsJS.buildFromOPParams(new OPParams(OPProxyCommands.OP_PROXY_PARAM_VALUE, OPProxyCommands.OP_PROXY_VALUE_TRUE));
        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_VISIBLE, trueParamsJS);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should have been called now", 1, view.setVisibleCalled);
        
        final OPParamsJS falseParamsJS = OPParamsJS.buildFromOPParams(new OPParams(OPProxyCommands.OP_PROXY_PARAM_VALUE, OPProxyCommands.OP_PROXY_VALUE_FALSE));
        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_VISIBLE, falseParamsJS);

        assertEquals("Handler should still not have been called now", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should have been called now", 2, view.setVisibleCalled);
    }
    
    /**
     * Test proxy command setVisible with invalid param. Should call the handler, not the view method.
    */
    public final void testProxyCommandSetVisibleWithInvalidParams() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.OP_PROXY_COMMAND_SET_VISIBLE, valueParamsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Test unknown proxy command (start with OPProxyCommands.PREFIX_OP_PROXY_COMMANDS). Should call the handler, not the view method.
    */
    public final void testUnknownProxyCommand() {
        proxy.addMessageHandler(handler);
        proxy.attachView(view);

        assertEquals("Handler should not have been called yet", 0, handler.counterOfTimeCalled);
        assertEquals("View.setStyleName should not have been called yet", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should not have been called yet", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should not have been called yet", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should not have been called yet", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should not have been called yet", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should not have been called yet", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should not have been called yet", 0, view.setWidthCalled);
        assertEquals("View.setHeight should not have been called yet", 0, view.setHeightCalled);
        assertEquals("View.setSize should not have been called yet", 0, view.setSizeCalled);
        assertEquals("View.setVisible should not have been called yet", 0, view.setVisibleCalled);

        dispatcher.dispatchMessageToEmbeddedView(OPProxyCommands.PREFIX_OP_PROXY_COMMANDS + "unknown", valueParamsjs);

        assertEquals("View.setStyleName should still not have been called now", 0, view.setStyleNameCalled);
        assertEquals("View.addStyleName should still not have been called now", 0, view.addStyleNameCalled);
        assertEquals("View.removeStyleName should still not have been called now", 0, view.removeStyleNameCalled);
        assertEquals("View.setStylePrimaryName should still not have been called now", 0, view.setStylePrimaryNameCalled);
        assertEquals("View.addStyleDependentName should still not have been called now", 0, view.addStyleDependentNameCalled);
        assertEquals("View.removeStyleDependentName should still not have been called now", 0, view.removeStyleDependentNameCalled);
        assertEquals("View.setWidth should still not have been called now", 0, view.setWidthCalled);
        assertEquals("View.setHeight should still not have been called now", 0, view.setHeightCalled);
        assertEquals("View.setSize should still not have been called now", 0, view.setSizeCalled);
        assertEquals("View.setVisible should still not have been called now", 0, view.setVisibleCalled);
        assertEquals("Handler should have been called now", 1, handler.counterOfTimeCalled);
    }
    
    /**
     * Dummy view to test proxy commands.
     */
    class DummyView extends Widget {

        public int addStyleDependentNameCalled = 0;
        public int addStyleNameCalled = 0;
        public int removeStyleDependentNameCalled = 0;
        public int removeStyleNameCalled = 0;
        public int setHeightCalled = 0;
        public int setSizeCalled = 0;
        public int setStyleNameCalled = 0;
        public int setStylePrimaryNameCalled = 0;
        public int setVisibleCalled = 0;
        public int setWidthCalled = 0;
        
        @Override
        public void addStyleDependentName(final String styleSuffix) {
            ++addStyleDependentNameCalled;
        }

        @Override
        public void addStyleName(final String style) {
            ++addStyleNameCalled;
        }

        @Override
        public void removeStyleDependentName(final String styleSuffix) {
            ++removeStyleDependentNameCalled;
        }

        @Override
        public void removeStyleName(final String style) {
            ++removeStyleNameCalled;
        }

        @Override
        public void setHeight(final String height) {
            ++setHeightCalled;
        }

        @Override
        public void setSize(final String width, final String height) {
            ++setSizeCalled;
        }

        @Override
        public void setStyleName(final String style) {
            ++setStyleNameCalled;
        }

        @Override
        public void setStylePrimaryName(final String style) {
            ++setStylePrimaryNameCalled;;
        }

        @Override
        public void setVisible(final boolean visible) {
            ++setVisibleCalled;
        }

        @Override
        public void setWidth(final String width) {
            ++setWidthCalled;
        }
        
    }
    
    /**
     * Dummy class implementing {@link OPMessageFromContainerSlotHandler}.
     */
    class DummyMessageFromContainerSlotHandler implements OPMessageFromContainerSlotHandler {

        public int counterOfTimeCalled = 0;
        public String message;
        public OPParams params;
        public int counterOfOnAttachCalled = 0;

        /**
         * Handle message from container slot.
         * 
         * @see fr.openparts.OpenParts.client.OPMessageFromContainerSlotHandler#handleMessageFromContainerSlot(java.lang.String,
         *      fr.openparts.OpenParts.client.OPParams)
         */
        @Override
        public void handleMessageFromContainerSlot(final String message, final OPParams params) {
            ++counterOfTimeCalled;
            this.message = message;
            this.params = params;
        }

        /**
         * Called when the embedded view is attached.
         * 
         * @see fr.openparts.OpenParts.client.OPMessageFromEmbeddedViewHandler#onEmbeddedViewAttach()
         */
        @Override
        public void onEmbeddedViewAttach() {
            ++counterOfOnAttachCalled;
        }
    }

    /**
     * Register a dummy view proxy in the dispatcher.
     * 
     * @param dispatcher
     *            the dispatcher on which to register the proxy.
     */
    private final native void registerDummyProxyInDispatcher(final OPMessagesDispatcher dispatcher) /*-{
        dispatcher.messageFromEmbeddedViewHandlerCallback = 1;
    }-*/;

    /**
     * Check if assertions are enabled.
     * 
     * @return true if assertions are enabled, false otherwise
     */
    private final boolean assertionsAreEnabled() {
        try {
            assert false;
            return false;
        } catch (AssertionError e) {
            return true;
        }
    }

}
